<?php
/*
 * stone pei added 
 * backend field validation rule
 */
function webform_validate_DE($elements, &$form_state) {
  // ---------------------Validate special for some required fields: Tanky -----------------------
  $PG_initiation_fieldset = 'pg_initiator_approver';
  $relocation_initiator = 'relocation_initiator_role';
  $is_approver = 'is_relocation_initiator_acting_as_approver';
  $attach_approval = 'please_attach_approval_notification';

  //print_r($form_state['values']['submitted'][$PG_initiation_fieldset]);exit;
  //print_r($elements);exit;
  if ($form_state['values']['submitted'][$PG_initiation_fieldset][$is_approver] == 1) {
    $ids_arr = array('edit-submitted-pg-initiator-approver-name-of-approver', 'edit-submitted-pg-initiator-approver-approver-email', 'edit-submitted-pg-initiator-approver-please-attach-approval-notification');
    if (in_array($elements['#id'], $ids_arr)) {
      return TRUE;
    }

    if (isset($elements['#type']) && $elements['#type'] == 'managed_file' && $elements['#webform_component']['form_key'] == $attach_approval) {
      //return;
    }
  }

  if ($form_state['values']['submitted'][$PG_initiation_fieldset][$relocation_initiator] == 'RLM') {
    $ids_arr = array('edit-submitted-pg-initiator-approver-name-of-receiving-line-manager', 'edit-submitted-pg-initiator-approver-receiving-line-manager-email', 'edit-submitted-pg-initiator-approver-not-rlm-confirm-info');
    if (in_array($elements['#id'], $ids_arr)) {
       return TRUE;
    }
  }else {
    $ids_arr = array('edit-submitted-pg-initiator-approver-rlm-confirm-info');
    if (in_array($elements['#id'], $ids_arr)) {
       return TRUE;
    }
  }
  // -----------------------------------------End-------------------------------------------------------
  
  // phase 2: add for Germany change by tanky
  $relocation_data_fieldset = 'relocation_data';
  $relocation_type = 'relocation_type';
  $sending_work_city = 'sending_work_city';
  $receiving_work_city = 'receiving_work_city';
  $relocation_type_newhire = 'new_hire';
  //print_r($form_state['values']['submitted'][$relocation_data_fieldset]);exit;
  // Sending Work Location/Site - Display if "Relocation Type" <> 'New Hire'
  if ($form_state['values']['submitted'][$relocation_data_fieldset][$relocation_type] == $relocation_type_newhire) {
      $ids_arr = array('edit-submitted-relocation-data-sending-work-location-site','edit-submitted-for-allowances-calculation-split-family');
      if (in_array($elements['#id'], $ids_arr)) {
        return TRUE;
      }
  }
  // Sending Work Location/city - Display if "Relocation Type" = 'New Hire'
  // Email Address 2 : Display if "Relocation Type" = 'New Hire'
  if ($form_state['values']['submitted'][$relocation_data_fieldset][$relocation_type] != $relocation_type_newhire) {
    $ids_arr = array('edit-submitted-relocation-data-sending-work-city', 'edit-submitted-personal-data-email-address-2');
    if (in_array($elements['#id'], $ids_arr)) {
        return TRUE;
    }
  }
  // Please specify sending city : only Display if "Sending Location/City" = 'Other'
  if ($form_state['values']['submitted'][$relocation_data_fieldset][$sending_work_city] != LOCATION_CITY_OTHERS) {
      $ids_arr = array('edit-submitted-relocation-data-please-specify-sending');
      if (in_array($elements['#id'], $ids_arr)) {
        return TRUE;
      }
  }
  // Please specify receiving city : only Display if "Receiving Location/City" = 'Other'
  if ($form_state['values']['submitted'][$relocation_data_fieldset][$receiving_work_city] != LOCATION_CITY_OTHERS) {
      $ids_arr = array('edit-submitted-relocation-data-please-specify-receiving');
      if (in_array($elements['#id'], $ids_arr)) {
        return TRUE;
      }
  }
  // phase 4 
  // please specify is spouse P&G employee
  $PG_allowance_fieldset='for_allowances_calculation';
  $is_spouse_employee='is_the_spouse_partner_a_pg_employee';
  if ($form_state['values']['submitted'][$PG_allowance_fieldset][$is_spouse_employee] == 2) {
      $ids_arr = array
      ('edit-submitted-for-allowances-calculation-if-yes-please-provide-spouse-partners-full-name',
        'edit-submitted-for-allowances-calculation-is-spouse-partner-also-being-transferred-1',
        'edit-submitted-for-allowances-calculation-is-spouse-partner-also-being-transferred-2',
        'edit-submitted-for-allowances-calculation-spouse-partners-sap-id-personnel-number');
      if (in_array($elements['#id'], $ids_arr)) {
        return TRUE;
      }
  }
    //Spouse/Partner's SAP ID/Personnel Number
  $is_spouse_partner_also_being_transferred='is_spouse_partner_also_being_transferred';
  if ($form_state['values']['submitted'][$PG_allowance_fieldset][$is_spouse_partner_also_being_transferred] != 1) {
    $ids_arr = array(
        'edit-submitted-for-allowances-calculation-spouse-partners-sap-id-personnel-number',
    );
    if (in_array($elements['#id'], $ids_arr)) {
       return TRUE;
    }
  }
  // SAP ID/Personnel Number : Non-mandatory if "Relocation Type" = 'New Hire'
  // P&G Email Address : Non-mandatory if "Relocation Type" = 'New Hire'
  if ($form_state['values']['submitted'][$relocation_data_fieldset][$relocation_type] == $relocation_type_newhire) {
      $ids_arr = array('edit-submitted-personal-data-global-sap-id', 'edit-submitted-personal-data-email-address');
      if (in_array($elements['#id'], $ids_arr)) {
        return TRUE;
      }
  }
     //legal entity none of above
  if ($form_state['values']['submitted'][$relocation_data_fieldset]['receiving_company_legal_entity2']['code'] != '0000'){
    $ids_arr = array(
      'edit-submitted-relocation-data-company-code',
    );
    if (in_array($elements['#id'], $ids_arr)) {
       return TRUE;
    }
  }
}

function webform_validate_JAP($elements, &$form_state) {
  // ---------------------Validate special for some required fields: Tanky -----------------------
  $PG_initiation_fieldset = 'pg_initiator_approver';
  $relocation_initiator = 'relocation_initiator_role';
  $is_approver = 'is_relocation_initiator_acting_as_approver';
  $attach_approval = 'please_attach_approval_notification';
 
  //print_r($form_state['values']['submitted'][$PG_initiation_fieldset]);exit;
  //print_r($elements);exit;
  if ($form_state['values']['submitted'][$PG_initiation_fieldset][$is_approver] == 1) {
    $ids_arr = array('edit-submitted-pg-initiator-approver-name-of-approver', 'edit-submitted-pg-initiator-approver-approver-email', 'edit-submitted-pg-initiator-approver-please-attach-approval-notification');
    if (in_array($elements['#id'], $ids_arr)) {
      return TRUE;
    }

    if (isset($elements['#type']) && $elements['#type'] == 'managed_file' && $elements['#webform_component']['form_key'] == $attach_approval) {
      //return;
    }
  }

  if ($form_state['values']['submitted'][$PG_initiation_fieldset][$relocation_initiator] == 'RLM') {
    $ids_arr = array('edit-submitted-pg-initiator-approver-name-of-receiving-line-manager', 'edit-submitted-pg-initiator-approver-receiving-line-manager-email', 'edit-submitted-pg-initiator-approver-not-rlm-confirm-info');
    if (in_array($elements['#id'], $ids_arr)) {
       return TRUE;
    }
  }else {
    $ids_arr = array('edit-submitted-pg-initiator-approver-rlm-confirm-info');
    if (in_array($elements['#id'], $ids_arr)) {
       return TRUE;
    }
  }
  // -----------------------------------------End-------------------------------------------------------
  
  // phase 2: add for Japan by tanky
  $relocation_data_fieldset = 'relocation_data';
  $relocation_type = 'relocation_type';
  $sending_work_city = 'sending_work_city';
  $receiving_work_city = 'receiving_work_city';
  $is_new_hire = 'is_the_employee_a_new_hire';
  $relocation_type_arr = array('temporary_bc_domestic', 'permanent_bc_domestic');
  //print_r($form_state['values']['submitted'][$relocation_data_fieldset]);exit;
  // Sending Work Location/Site - 2 Non-mandatory if "Relocation Type" = 'Temporary BC Domestic Relocation' or 'Permanent BC Domestic Relocation' 
  // Receiving Work Location/Site - Non-mandatory if "Relocation Type" = 'Temporary BC Domestic Relocation' or 'Permanent BC Domestic Relocation' 
  if (in_array($form_state['values']['submitted'][$relocation_data_fieldset][$relocation_type], $relocation_type_arr)) {
      $ids_arr = array('edit-submitted-relocation-data-sending-work-location-site', 'edit-submitted-relocation-data-receiving-work-location-site');
      if (in_array($elements['#id'], $ids_arr)) {
        return TRUE;
      }
  }
  // Sending Work Location/Site - 1 Only Display if "Is the employee a New Hire" = 'N'
  if ($form_state['values']['submitted'][$relocation_data_fieldset][$is_new_hire] == 1) {
    $ids_arr = array('edit-submitted-relocation-data-sending-work-location-site');
    if (in_array($elements['#id'], $ids_arr)) {
        return TRUE;
    }
  }
  // Sending Location/City : only Display if "Is the employee a New Hire" = 'Y'
  if ($form_state['values']['submitted'][$relocation_data_fieldset][$is_new_hire] != 1) {
      $ids_arr = array('edit-submitted-relocation-data-sending-work-city');
      if (in_array($elements['#id'], $ids_arr)) {
        return TRUE;
      }
  }
  // Please specify sending city : only Display if "Sending Location/City" = 'Other'
  if ($form_state['values']['submitted'][$relocation_data_fieldset][$sending_work_city] != LOCATION_CITY_OTHERS) {
      $ids_arr = array('edit-submitted-relocation-data-please-specify-sending');
      if (in_array($elements['#id'], $ids_arr)) {
        return TRUE;
      }
  }
  // Please specify receiving city : only Display if "Receiving Location/City" = 'Other'
  if ($form_state['values']['submitted'][$relocation_data_fieldset][$receiving_work_city] != LOCATION_CITY_OTHERS) {
      $ids_arr = array('edit-submitted-relocation-data-please-specify-receiving');
      if (in_array($elements['#id'], $ids_arr)) {
        return TRUE;
      }
  }
  // SAP ID/Personnel Number : Non-mandatory if "Is the employee a New Hire" = 'Y'
  if ($form_state['values']['submitted'][$relocation_data_fieldset][$is_new_hire] == 1) {
      $ids_arr = array('edit-submitted-personal-data-global-sap-id');
      if (in_array($elements['#id'], $ids_arr)) {
        return TRUE;
      }
  }
  // P&G Email Address : Non-mandatory if "Relocation Type" = 'Temporary BC Domestic Relocation' or 'Permanent BC Domestic Relocation', AND "Is the employee a New Hire" = 'Y'
  if (in_array($form_state['values']['submitted'][$relocation_data_fieldset][$relocation_type], $relocation_type_arr) 
          && $form_state['values']['submitted'][$relocation_data_fieldset][$is_new_hire] == 1) {
      $ids_arr = array('edit-submitted-personal-data-email-address');
      if (in_array($elements['#id'], $ids_arr)) {
        return TRUE;
      }
  }
  else {
      // Email Address : Only display if "Relocation Type" = 'Temporary BC Domestic Relocation' or 'Permanent BC Domestic Relocation', AND "Is the employee a New Hire" = 'Y'
      $ids_arr = array('edit-submitted-personal-data-email-address-2');
      if (in_array($elements['#id'], $ids_arr)) {
        return TRUE;
      }
  }
     //legal entity none of above
  if ($form_state['values']['submitted'][$relocation_data_fieldset]['receiving_company_legal_entity2']['code'] != '0000'){
    $ids_arr = array(
      'edit-submitted-relocation-data-company-code',
    );
    if (in_array($elements['#id'], $ids_arr)) {
       return TRUE;
    }
  }
}

function webform_validate_MEX($elements, &$form_state) {
    // ---------------------Validate special for some required fields: Tanky -----------------------
  $PG_initiation_fieldset = 'pg_initiator_approver';
  $relocation_initiator = 'relocation_initiator_role';
  $is_approver = 'is_relocation_initiator_acting_as_approver';
  $attach_approval = 'please_attach_approval_notification';

  //print_r($form_state['values']['submitted'][$PG_initiation_fieldset]);exit;
  //print_r($elements);exit;
  if ($form_state['values']['submitted'][$PG_initiation_fieldset][$is_approver] == 1) {
    $ids_arr = array('edit-submitted-pg-initiator-approver-name-of-approver', 'edit-submitted-pg-initiator-approver-approver-email', 'edit-submitted-pg-initiator-approver-please-attach-approval-notification');
    if (in_array($elements['#id'], $ids_arr)) {
      return TRUE;
    }

    if (isset($elements['#type']) && $elements['#type'] == 'managed_file' && $elements['#webform_component']['form_key'] == $attach_approval) {
      //return;
    }
  }

  if ($form_state['values']['submitted'][$PG_initiation_fieldset][$relocation_initiator] == 'RLM') {
    $ids_arr = array('edit-submitted-pg-initiator-approver-name-of-receiving-line-manager', 'edit-submitted-pg-initiator-approver-receiving-line-manager-email', 'edit-submitted-pg-initiator-approver-not-rlm-confirm-info');
    if (in_array($elements['#id'], $ids_arr)) {
       return TRUE;
    }
  }else {
    $ids_arr = array('edit-submitted-pg-initiator-approver-rlm-confirm-info');
    if (in_array($elements['#id'], $ids_arr)) {
       return TRUE;
    }
  }
  // -----------------------------------------End-------------------------------------------------------
  
  // new added logic :  if is new hire: 
  // no mondortry fields: Sending Work Location/Site
  $relocation_data_fieldset = 'relocation_data';
  $is_new_hire = 'is_the_employee_a_new_hire';
  if ($form_state['values']['submitted'][$relocation_data_fieldset][$is_new_hire] == 1) {
    $ids_arr = array(
      'edit-submitted-relocation-data-sending-work-location-site',
      'edit-submitted-personal-data-global-sap-id',
      'edit-submitted-personal-data-email-address',
    );
    if (in_array($elements['#id'], $ids_arr)) {
       return TRUE;
    }   
  }
  else{
    // not new hire:
    $ids_arr = array(
      'edit-submitted-personal-data-email-address-2',
      'edit-submitted-relocation-data-sending-work-city',
    );
    if (in_array($elements['#id'], $ids_arr)) {
       return TRUE;
    }
  }
  // location city others:
  $sending_location_city = 'sending_work_city';
  $receiving_location_city = 'receiving_work_city';
  if ($form_state['values']['submitted'][$relocation_data_fieldset][$sending_location_city] != LOCATION_CITY_OTHERS){
    $ids_arr = array(
      'edit-submitted-relocation-data-please-specify-sending',
    );
    if (in_array($elements['#id'], $ids_arr)) {
       return TRUE;
    }
  }
  if ($form_state['values']['submitted'][$relocation_data_fieldset][$receiving_location_city] != LOCATION_CITY_OTHERS){
    $ids_arr = array(
      'edit-submitted-relocation-data-please-specify-receiving',
    );
    if (in_array($elements['#id'], $ids_arr)) {
       return TRUE;
    }
  }
  
  //Is the Spouse/Partner a P&G Employee 
  $for_allowances_calculation = 'for_allowances_calculation';
  $is_the_spouse_partner_yes_val =  'is_the_spouse_partner_a_pg_employee';
  if ($form_state['values']['submitted'][$for_allowances_calculation][$is_the_spouse_partner_yes_val] != 1) {
    $ids_arr = array(
        'edit-submitted-for-allowances-calculation-if-yes-please-provide-spouse-partners-full-name',
        'edit-submitted-for-allowances-calculation-spouse-partners-sap-id-personnel-number',
        'edit-submitted-for-allowances-calculation-is-spouse-partner-also-being-transferred',
    );
    if (in_array($elements['#id'], $ids_arr)) {
       return TRUE;
    }
  }
  //Spouse/Partner's SAP ID/Personnel Number
  $is_spouse_partner_also_being_transferred='is_spouse_partner_also_being_transferred';
  if ($form_state['values']['submitted'][$for_allowances_calculation][$is_spouse_partner_also_being_transferred] != 1) {
    $ids_arr = array(
        'edit-submitted-for-allowances-calculation-spouse-partners-sap-id-personnel-number',
    );
    if (in_array($elements['#id'], $ids_arr)) {
       return TRUE;
    }
  }
    //legal entity none of above
  if ($form_state['values']['submitted'][$relocation_data_fieldset]['receiving_company_legal_entity2']['code'] != '0000'){
    $ids_arr = array(
      'edit-submitted-relocation-data-company-code',
    );
    if (in_array($elements['#id'], $ids_arr)) {
       return TRUE;
    }
  }
  
}

function webform_validate_TUR($elements, &$form_state) {
  // ---------------------Validate special for some required fields: Tanky -----------------------
  $PG_initiation_fieldset = 'pg_initiator_approver';
  $relocation_initiator = 'relocation_initiator_role';
  $is_approver = 'is_relocation_initiator_acting_as_approver';
  $attach_approval = 'please_attach_approval_notification';

  //print_r($form_state['values']['submitted'][$PG_initiation_fieldset]);exit;
  //print_r($elements);exit;
  if ($form_state['values']['submitted'][$PG_initiation_fieldset][$is_approver] == 1) {
    $ids_arr = array('edit-submitted-pg-initiator-approver-name-of-approver', 'edit-submitted-pg-initiator-approver-approver-email', 'edit-submitted-pg-initiator-approver-please-attach-approval-notification');
    if (in_array($elements['#id'], $ids_arr)) {
      return TRUE;
    }

    if (isset($elements['#type']) && $elements['#type'] == 'managed_file' && $elements['#webform_component']['form_key'] == $attach_approval) {
      //return;
    }
  }

  if ($form_state['values']['submitted'][$PG_initiation_fieldset][$relocation_initiator] == 'RLM') {
    $ids_arr = array('edit-submitted-pg-initiator-approver-name-of-receiving-line-manager', 'edit-submitted-pg-initiator-approver-receiving-line-manager-email', 'edit-submitted-pg-initiator-approver-not-rlm-confirm-info');
    if (in_array($elements['#id'], $ids_arr)) {
       return TRUE;
    }
  }else {
    $ids_arr = array('edit-submitted-pg-initiator-approver-rlm-confirm-info');
    if (in_array($elements['#id'], $ids_arr)) {
       return TRUE;
    }
  }
  // -----------------------------------------End-------------------------------------------------------
  
  // phase 2: add for Germany change by tanky
  $relocation_data_fieldset = 'relocation_data';
  $relocation_type = 'relocation_type';
  $sending_work_city = 'sending_work_city';
  $receiving_work_city = 'receiving_work_city';
  $relocation_type_newhire = 'new_hire';
  //print_r($form_state['values']['submitted'][$relocation_data_fieldset]);exit;
  // Sending Work Location/Site - Display if "Relocation Type" <> 'New Hire'
  if ($form_state['values']['submitted'][$relocation_data_fieldset][$relocation_type] == $relocation_type_newhire) {
      $ids_arr = array('edit-submitted-relocation-data-sending-work-location-site');
      if (in_array($elements['#id'], $ids_arr)) {
        return TRUE;
      }
  }
  // Sending Work Location/city - Display if "Relocation Type" = 'New Hire'
  // Email Address 2 : Display if "Relocation Type" = 'New Hire'
  if ($form_state['values']['submitted'][$relocation_data_fieldset][$relocation_type] != $relocation_type_newhire) {
    $ids_arr = array('edit-submitted-relocation-data-sending-work-city', 'edit-submitted-personal-data-email-address-2');
    if (in_array($elements['#id'], $ids_arr)) {
        return TRUE;
    }
  }
  // Please specify sending city : only Display if "Sending Location/City" = 'Other'
  if ($form_state['values']['submitted'][$relocation_data_fieldset][$sending_work_city] != LOCATION_CITY_OTHERS) {
      $ids_arr = array('edit-submitted-relocation-data-please-specify-sending');
      if (in_array($elements['#id'], $ids_arr)) {
        return TRUE;
      }
  }
  // Please specify receiving city : only Display if "Receiving Location/City" = 'Other'
  if ($form_state['values']['submitted'][$relocation_data_fieldset][$receiving_work_city] != LOCATION_CITY_OTHERS) {
      $ids_arr = array('edit-submitted-relocation-data-please-specify-receiving');
      if (in_array($elements['#id'], $ids_arr)) {
        return TRUE;
      }
  }
  // SAP ID/Personnel Number : Non-mandatory if "Relocation Type" = 'New Hire'
  // P&G Email Address : Non-mandatory if "Relocation Type" = 'New Hire'
  if ($form_state['values']['submitted'][$relocation_data_fieldset][$relocation_type] == $relocation_type_newhire) {
      $ids_arr = array('edit-submitted-personal-data-global-sap-id', 'edit-submitted-personal-data-email-address');
      if (in_array($elements['#id'], $ids_arr)) {
        return TRUE;
      }
  }
    //legal entity none of above
  if ($form_state['values']['submitted'][$relocation_data_fieldset]['receiving_company_legal_entity2']['code'] != '0000'){
    $ids_arr = array(
      'edit-submitted-relocation-data-company-code',
    );
    if (in_array($elements['#id'], $ids_arr)) {
       return TRUE;
    }
  }
}


function webform_validate_AU($elements, &$form_state) {
    // ---------------------Validate special for some required fields: Tanky -----------------------
  $PG_initiation_fieldset = 'pg_initiator_approver';
  $relocation_initiator = 'relocation_initiator_role';
  $is_approver = 'is_relocation_initiator_acting_as_approver';
  $attach_approval = 'please_attach_approval_notification';

  //print_r($form_state['values']['submitted'][$PG_initiation_fieldset]);exit;
  //print_r($elements);exit;
  if ($form_state['values']['submitted']['country_of_domestic_transfer'] == "CN") {
    $ids_arr = array(
        'edit-submitted-relocation-data-sending-work-city',
        'edit-submitted-relocation-data-sending-work-location-site',
        'edit-submitted-pg-initiator-approver-is-relocation-initiator-acting-as-approver',
        );
    if (in_array($elements['#id'], $ids_arr)) {
      return TRUE;
    }
  }
  if ($form_state['values']['submitted'][$PG_initiation_fieldset][$is_approver] == 1||$form_state['values']['submitted']['country_of_domestic_transfer'] == "CN") {
    $ids_arr = array('edit-submitted-pg-initiator-approver-name-of-approver', 'edit-submitted-pg-initiator-approver-approver-email', 'edit-submitted-pg-initiator-approver-please-attach-approval-notification');
    if (in_array($elements['#id'], $ids_arr)) {
      return TRUE;
    }

    if (isset($elements['#type']) && $elements['#type'] == 'managed_file' && $elements['#webform_component']['form_key'] == $attach_approval) {
      //return;
    }
  }

  if ($form_state['values']['submitted'][$PG_initiation_fieldset][$relocation_initiator] == 'RLM') {
    $ids_arr = array('edit-submitted-pg-initiator-approver-name-of-receiving-line-manager', 'edit-submitted-pg-initiator-approver-receiving-line-manager-email', 'edit-submitted-pg-initiator-approver-not-rlm-confirm-info');
    if (in_array($elements['#id'], $ids_arr)) {
       return TRUE;
    }
  }else {
    $ids_arr = array('edit-submitted-pg-initiator-approver-rlm-confirm-info');
    if (in_array($elements['#id'], $ids_arr)) {
       return TRUE;
    }
  }
  // -----------------------------------------End-------------------------------------------------------
  
  // new added logic :  if is new hire: 
  // no mondortry fields: Sending Work Location/Site
  $relocation_data_fieldset = 'relocation_data';
  $is_new_hire = 'is_the_employee_a_new_hire';
  if ($form_state['values']['submitted'][$relocation_data_fieldset][$is_new_hire] == 1) {
    $ids_arr = array(
      'edit-submitted-relocation-data-sending-work-location-site',
      'edit-submitted-personal-data-global-sap-id',
      'edit-submitted-personal-data-email-address',
    );
    if (in_array($elements['#id'], $ids_arr)) {
       return TRUE;
    }   
  }
  else{
    // not new hire:
    $ids_arr = array(
      'edit-submitted-personal-data-email-address-2',
      'edit-submitted-relocation-data-sending-work-city',
    );
    if (in_array($elements['#id'], $ids_arr)) {
       return TRUE;
    }
  }
  // location city others:
  $sending_location_city = 'sending_work_city';
  $receiving_location_city = 'receiving_work_city';
  if ($form_state['values']['submitted'][$relocation_data_fieldset][$sending_location_city] != LOCATION_CITY_OTHERS){
    $ids_arr = array(
      'edit-submitted-relocation-data-please-specify-sending',
    );
    if (in_array($elements['#id'], $ids_arr)) {
       return TRUE;
    }
  }
  if ($form_state['values']['submitted'][$relocation_data_fieldset][$receiving_location_city] != LOCATION_CITY_OTHERS){
    $ids_arr = array(
      'edit-submitted-relocation-data-please-specify-receiving',
    );
    if (in_array($elements['#id'], $ids_arr)) {
       return TRUE;
    }
  }
  
  //Personal Data function and If CBD 
  if ($form_state['values']['submitted']['country_of_domestic_transfer'] != "CN"||$form_state['values']['submitted']['function']!='cn_CUSTOMER_BUSINESS_DEVELOPMENT_SALES') {
      
    $ids_arr = array(
        'edit-submitted-personal-data-if-cbd-please-provide-long-term-career-base',
        'edit-submitted-personal-data-function',
    );
    if (in_array($elements['#id'], $ids_arr)) {
       return TRUE;
    }
  }
  //Is the Spouse/Partner a P&G Employee 
  $for_allowances_calculation = 'for_allowances_calculation';
  $is_the_spouse_partner_yes_val =  'is_the_spouse_partner_a_pg_employee';
  if ($form_state['values']['submitted'][$for_allowances_calculation][$is_the_spouse_partner_yes_val] != 1) {
    $ids_arr = array(
        'edit-submitted-for-allowances-calculation-if-yes-please-provide-spouse-partners-full-name',
        'edit-submitted-for-allowances-calculation-spouse-partners-sap-id-personnel-number',
        'edit-submitted-for-allowances-calculation-is-spouse-partner-also-being-transferred',
    );
    if (in_array($elements['#id'], $ids_arr)) {
       return TRUE;
    }
  }
  //Spouse/Partner's SAP ID/Personnel Number
  $is_spouse_partner_also_being_transferred='is_spouse_partner_also_being_transferred';
  if ($form_state['values']['submitted'][$for_allowances_calculation][$is_spouse_partner_also_being_transferred] != 1) {
    $ids_arr = array(
        'edit-submitted-for-allowances-calculation-spouse-partners-sap-id-personnel-number',
    );
    if (in_array($elements['#id'], $ids_arr)) {
       return TRUE;
    }
  }
     //legal entity none of above
  if ($form_state['values']['submitted'][$relocation_data_fieldset]['receiving_company_legal_entity2']['code'] != '0000'){
    $ids_arr = array(
      'edit-submitted-relocation-data-company-code',
    );
    if (in_array($elements['#id'], $ids_arr)) {
       return TRUE;
    }
  }
  
}
